package org.meproj.cloudscale.algos;

public class UnderEstimationCorrection {

	private float resourcePressure = 0f;
	private float minAlpha;
	private float maxAlpha;
	private float riskAppetite;

	public UnderEstimationCorrection(int resourceUsage, int resourceCap, float minAlpha, float maxAlpha) {
		super();
		this.minAlpha = minAlpha;
		this.maxAlpha = maxAlpha;
		
		resourcePressure = resourceUsage / resourceCap;
	}

	public float calculateAlpha() {
		float currentAlpha = 1f;
		float resourcePressureThreshold = 1 - (riskAppetite / 100);
		
		if(resourcePressure > resourcePressureThreshold) {
			float numerator = resourcePressure - resourcePressureThreshold ;
			float denominator = 1 - resourcePressureThreshold;
			
			currentAlpha = ((numerator/denominator) * (maxAlpha-minAlpha)) + minAlpha;
		}
		
		return currentAlpha;
	}
}